package 面向对象.battleGame;

import java.util.Random;

public class RolePro {

    private String name;
    private int hp;
    private char gender;
    private String face;//长相随机生成

    String[] boyfaces={"风流俊雅", "气宇轩昂", "相貌英俊", "五官端正", "相貌平平", "一塌糊涂", "面目狰狞"};
    String[] girlfaces={"美奂绝伦", "沉鱼落雁", "婷婷玉立", "身材娇好", "相貌平平", "相貌简陋", "惨不忍睹"};
    String[] attacks_desc={
            "%s使出了【影分身十字斩】，挥刀向%s砍去。",
            "%s使出了【岚刀一直切】，连续挥舞刀刃杀向%s。",
            "%s使出了【奥义·升龙】，消耗大量蕾克拉召唤出了一条神龙，冲向%s。",
            "%s消耗大量蕾克拉，一瞬间刀刃燃起火焰，一招【一刀一刀燃烧刀】，杀向%s。",
            "%s翻手跟进，一招【往事如烟手】，结结实实地拍向%s。",
            "%s上步抢身，招中套招，一招【纳米悠悠球】，连环攻向%s。"
    };

    String[] injureds_desc={
            "结果%s退了半步，毫发无损",
            "结果给%s造成一处瘀伤",
            "结果一击命中，%s痛得弯下腰",
            "结果%s痛苦地闷哼了一声，显然受了点内伤",
            "结果%s摇摇晃晃，一跤摔倒在地",
            "结果%s脸色一下变得惨白，连退了好几步",
            "结果『轰』的一声，%s口中鲜血狂喷而出",
            "结果%s一声惨叫，像滩软泥般塌了下去"
    };
    public RolePro() {
    }

    public RolePro(String name, int hp, char gender) {
        this.name = name;
        this.hp = hp;
        this.gender = gender;
        setFace(gender);
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getHp() {
        return hp;
    }

    public void setHp(int hp) {
        this.hp = hp;
    }

    public char getGender() {
        return gender;
    }

    public void setGender(char gender) {
        this.gender = gender;
    }

    public String getFace() {
        return face;
    }

    public void setFace(char gender) {
        Random r = new Random();

        if (gender == '男') {

            int index = r.nextInt(boyfaces.length);
            this.face = boyfaces[index];

        } else if (gender == '女') {

            int index = r.nextInt(girlfaces.length);
            this.face = girlfaces[index];

        } else {
            this.face = "面目狰狞";
        }
    }

    //方法调用者攻击参数
    public void attack(RolePro role) {

        //随机选择一个攻击效果
        Random r = new Random();
        int index = r.nextInt(attacks_desc.length);
        String RenShu = attacks_desc[index];

        //计算造成的伤害，是0-799之间的随机数
        int atk = r.nextInt(800);

        //修改被攻击方的生命值
        int newHp = role.getHp() - atk;
        //如果生命值小于0，修改为0
        if (newHp < 0) {
            role.setHp(0);
        } else {
            role.setHp(newHp);
        }

        //输出一个攻击效果
        System.out.printf(RenShu + "造成了" + atk + "点伤害",this.getName(),role.getName());
        System.out.println();

        //根据生命值选择一个受伤效果
        if (role.getHp() > 1800) {
            System.out.printf(injureds_desc[0],role.getName());
        } else if (role.getHp() > 1600) {
            System.out.printf(injureds_desc[1],role.getName());
        } else if (role.getHp() > 1400) {
            System.out.printf(injureds_desc[2], role.getName());
        } else if (role.getHp() > 1200) {
            System.out.printf(injureds_desc[3], role.getName());
        } else if (role.getHp() > 800) {
            System.out.printf(injureds_desc[4], role.getName());
        } else if (role.getHp() > 400) {
            System.out.printf(injureds_desc[5], role.getName());
        } else if (role.getHp() > 200) {
            System.out.printf(injureds_desc[6], role.getName());
        } else {
            System.out.printf(injureds_desc[7], role.getName());
        }
        System.out.println();

    }

    //展示角色信息
    public void show() {
        System.out.println("姓名：" + getName());
        System.out.println("性别：" + getGender());
        System.out.println("长相：" + getFace());
        System.out.println("生命值：" + getHp());
    }
}
